package com.glink.common.serializer;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.glink.common.util.BaseCommonUtils;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 *
 * @author andy.ren
 * Created by rencl on 2017/12/27.
 */
public class JsonDateHourMinSecDeSerializer extends JsonDeserializer<Date> {
    @Override
    public Date deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) {
        try {
            if (StringUtils.hasLength(jsonParser.getText())) {
                return BaseCommonUtils.DATE_FORMAT_HOUR_MI_SECOND.parse(jsonParser.getText());
            } else {
                return null;
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
            throw new RuntimeException(e);
        }
    }
}
